package com.twm.exception;
/**
 *  做异常定位
 * @ClassName AbnormalPositioning
 * @Description TODO
 * @Author twm17
 * @Date 2020/8/26 18:07
 * @Version 1.0
 */
public class AbnormalPositioning {
    private AbnormalPositioning(){}

    /**
     * 过去错误的行号和异常类型
     * @param e 1
     * @return java.lang.String
     * @author twm
     * @date 2020/8/28
     */
    public static String getExceptionLineNumberAndMethodName(Exception e) {
        if(e == null) {
            return null;
        }
        StringBuffer buffer = new StringBuffer();
        StackTraceElement[] stacks = e.getStackTrace();
        int lineNumber = stacks[0].getLineNumber();
        String methodName = stacks[0].getMethodName();
        buffer.append("当前异常的行数:"+lineNumber+"---");
        buffer.append("当前异常的方法:" +methodName+ "----");
        buffer.append("当前异常的类型:"+e.getMessage());
        return buffer.toString();
    }
}
